package easier.log.logger;

import android.content.Context;
import android.content.pm.PackageManager.NameNotFoundException;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/**
 * 用于显示测试log
 */
public class AndroidLogAdapterImpl extends AndroidLogAdapter {

    private boolean log = false;

    public AndroidLogAdapterImpl( Context context ) {

        init( context );
    }

    public AndroidLogAdapterImpl( Context context, @NonNull FormatStrategy formatStrategy ) {

        super( formatStrategy );
        init( context );
    }

    private void init( Context context ) {

        try {
            String versionName = context.getPackageManager().getPackageInfo( context.getPackageName(), 0 ).versionName;
            log = versionName.toLowerCase().contains( "test" );
        } catch ( NameNotFoundException e ) {
            e.printStackTrace();
        }
    }

    @Override
    public boolean isLoggable( int priority, @Nullable String tag ) {

        return log;
    }
}
